﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Web;

namespace Support
{
    public class DownloadFile
    {
        public string DownloadValidateImg(string url)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "downloads\\validate";
            if (!Directory.Exists(path))
            {
                try
                {
                    Directory.CreateDirectory(path);
                }
                catch 
                {
                    return "";
                }
            }
            string fileName = DateTime.Now.Ticks.ToString() + ".jpg";
            string filePath = path + "\\" + fileName;
            HttpClient hc = new HttpClient();
            try
            {
                hc.DownloadFile(url, filePath);
            }
            catch
            {
                return "";
            }
            return "/downloads/validate/" + fileName;
        }
    }
}
